# 被定义在一对{}的数据，称为字典dict
# { key:value, key:value, key:value }
# 可变！！！！！！！！！！！！！

data_01 = {}
data_02 = { "nginx":"1.20", "tomcat":"9.10" }
data_03 = { "martin":"BJ", "demon":"sh", "leah":"hb" }
data_04 = {
    "10.1.1.1": {
      "ssh_user": "admin",
      "ssh_password": "redhat",
      "ssh_port": 22
    },
    "10.1.1.2": {
        "ssh_user": "martin",
        "ssh_password": "123",
        "ssh_port": 22345
    }
}
print(type(data_01), type(data_02), type(data_03), type(data_04))

print("-----------" * 8)

# 1、取数据， 字典.get()
data_02 = { "nginx":"1.20", "tomcat":"9.10" }

print(data_02["tomcat"])

version = data_02.get("nginx")
print(version)

print("-----------" * 8)

# 2、添加数据   字典[key] = value
data_02["redis"] = "5.0"
print(data_02)

print("-----------" * 8)

# 3、修改数据    字典[key] = value
data_02["nginx"] = "1.18"
print(data_02)

print("-----------" * 8)

# 4、获取字典中所有的key   字典.keys()
data_02 = { "nginx":"1.20", "tomcat":"9.10", "redis":"5.0" }
print(data_02.keys())

print("-----------" * 8)

# 5. 字典.items()， 用于遍历字典
data_02 = { "nginx":"1.20", "tomcat":"9.10", "redis":"5.0" }
print(data_02.items())

for k, v in data_02.items():
    print("软件名称: %s, 版本: %s" % (k, v))

print("-----------" * 8)

data_04 = {
    "10.1.1.1": {
      "ssh_user": "admin",
      "ssh_password": "redhat",
      "ssh_port": 22
    },
    "10.1.1.2": {
        "ssh_user": "martin",
        "ssh_password": "123",
        "ssh_port": 22345
    }
}
# ssh 用户名@IP -p 端口
for ip, info in data_04.items():
    print("ssh %s@%s -p %s" % (info.get("ssh_user"), ip, info.get("ssh_port")))


